#include "gameselect.h"
#include"gamehall.h"
#include"gameroom.h"
#include<QPainter>
#include<QPixmap>
#include<QPushButton>
#include<QIcon>
#include<QSound>
#include<QTextEdit>
#include<QFile>
#include<QFont>
#include<QTextStream>
gameSelect::gameSelect(QWidget *parent) : QWidget(parent)
{
    //设置当前窗口的标题，图标
    this->setWindowTitle("选择关卡");
    this->setWindowIcon(QIcon(":res/menu.png"));

    //创建返回图标
    QPushButton* backButton = new QPushButton(this);
    backButton->setIcon(QIcon(":res/back.png"));
    backButton->resize(50,50);
    backButton->move(900,700);

    //按下按钮返回初始菜单
    connect(backButton,&QPushButton::clicked,[=](){
        this->close();
        gamehall* gameHall = new gamehall;
        gameHall->show();

        QSound::play(":res/clicked.wav");
    });

    //创建游戏窗口
    gameroom* gameRoom = new gameroom;

    //创建格式
    QFont font("新宋体",20);


    //创建模式按钮
    QPushButton* easyButton = new QPushButton(this);
    easyButton->setText("简单模式");
    //easyButton->resize(200,80);
    easyButton->setFont(font);
    easyButton->move(400,150);
    //建立链接
    connect(easyButton,&QPushButton::clicked,[=](){
        gameRoom->show();
        gameRoom->setGeometry(this->geometry());
        this->close();
        QSound::play(":res/clicked.wav");
        gameRoom->setMoveSpeed(300);
    });

    QPushButton* simpleButton = new QPushButton(this);
    simpleButton->setText("普通模式");
    //simpleButton->resize(200,80);
    simpleButton->setFont(font);
    simpleButton->move(400,250);
    //建立链接
    connect(simpleButton,&QPushButton::clicked,[=](){
        gameRoom->show();
        gameRoom->setGeometry(this->geometry());
        this->close();
        QSound::play(":res/clicked.wav");
        gameRoom->setMoveSpeed(200);
    });


    QPushButton* hardButton = new QPushButton(this);
    hardButton->setText("困难模式");
    //hardButton->resize(200,80);
    hardButton->setFont(font);
    hardButton->move(400,350);
    //建立链接
    connect(hardButton,&QPushButton::clicked,[=](){
        gameRoom->show();
        gameRoom->setGeometry(this->geometry());
        this->close();
        QSound::play(":res/clicked.wav");
        gameRoom->setMoveSpeed(100);
    });


    QPushButton* hisButton = new QPushButton(this);
    hisButton->setText("历史战绩");
    //hisButton->resize(200,80);
    hisButton->setFont(font);
    hisButton->move(400,450);

    connect(hisButton,&QPushButton::clicked,[=](){
        QWidget* widget = new QWidget(this);
        widget->setWindowTitle("历史战绩");
        widget->setFixedSize(500,300);

        QTextEdit* edit = new QTextEdit(widget);
        edit->setFont(font);
        edit->setFixedSize(500,300);

        //QFile file(‪"‪D:/qt/1.txt";);
        //file.open(QIODevice::ReadOnly);

        //QTextStream in(&file);
        //int data = in.readLine().toInt();

        //edit->append(QString::number(data));

        widget->show();
    });

}

void gameSelect::paintEvent(QPaintEvent *event)
{
    (void)event;
    QPainter painter(this);

    QPixmap pixmap(":res/selectMenu.png");

    painter.drawPixmap(0,0,this->width(),this->height(),pixmap);
}
